package com.aaa.goodsservice.service;

import com.aaa.common.entity.Order;
import com.aaa.goodsservice.mapper.GoodsMapper;
import com.aaa.goodsservice.po.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author: YuXin
 * @Date : Created in 2020/11/3 17:02
 * @ClassName : GoodsServiceImpl
 * @Description :
 * @Package_Name : com.aaa.goodsservice.service
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private RestTemplate restTemplate;

    @Override
    public List<Product> selectAll() {
        return goodsMapper.selectAll();
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return goodsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Product record) {
        return goodsMapper.insert(record);
    }

    @Override
    public int insertSelective(Product record) {
        return goodsMapper.insertSelective(record);
    }

    @Override
    public Product selectByPrimaryKey(Long id) {
        return goodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Product record) {
        return goodsMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Product record) {
        return goodsMapper.updateByPrimaryKey(record);
    }

    /**
     * 对HTTP和TCP客户端的行为进行大量空值
     * orderService 必须和调用的服务的向注册中心应用名称一致
     * /order/selectAll  必须和调用服务的方法请求url一致
     */
    @Override
    public List<Order> selectAllOrder() {
        return restTemplate.getForObject("http://orderService/order/selectAll", List.class);
    }
}
